<?php
/**
 * Created by yd
 * User: xiaojun.lan
 * Date: 2018/5/15
 * Time: 17:10
 */

namespace app\server\controller;

use Workerman\Worker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use GatewayWorker\BusinessWorker;


class Server
{

    /**
     * 构造函数
     * @access public
     */
    public function __construct(){

        //初始化各个GatewayWorker
        //初始化register register 服务必须是text协议
        $register = new Register('text://0.0.0.0:1236');


        //初始化 bussinessWorker 进程
        $worker = new BusinessWorker();
        // worker名称
        $worker->name = 'ChatBusinessWorker';
        // bussinessWorker进程数量
        $worker->count = 4;
        // 服务注册地址
        $worker->registerAddress = '127.0.0.1:1236';
        //设置处理业务的类,此处制定Events的命名空间
        $worker->eventHandler = 'app\server\controller\Events';


        // 初始化 gateway 进程 ， 客户端连接Gateway
        $gateway = new Gateway("websocket://0.0.0.0:7272");
        // 设置名称，方便status时查看
        $gateway->name = 'ChatGateway';
        $gateway->count = 4;
        // 分布式部署时请设置成内网ip（非127.0.0.1）
        $gateway->lanIp = '172.17.249.223';
        // 内部通讯起始端口，假如$gateway->count=4，起始端口为4000
        // 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
        $gateway->startPort = 2300;
        // 心跳间隔
        $gateway->pingInterval = 10;
        // 心跳数据
        $gateway->pingData = '{"type":"ping"}';
        // 服务注册地址
        $gateway->registerAddress = '127.0.0.1:1236';

        //运行所有Worker;
        Worker::runAll();


    }

}
